package com.lp.biz.operations.controller;

import com.lp.biz.operations.service.BizAuthApplyService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.SPECIAL_APPLY;

/**
 * BizAuthApplyController
 * @program: backend
 * @author Ke.Song
 * @since 2024-08-08 23:28:07
 */
@RestController
@RequestMapping("/auth-apply")
public class BizAuthApplyController {

    @Autowired
    private BizAuthApplyService applyService;

    /**
     * 特别申请列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("")
    @PermissionAnnotation(menus = {SPECIAL_APPLY})
    public CommonResult getApplyList(PageParams query) {
        return applyService.getApplyList(query);
    }

    /**
     * 同意特别申请
     * @param applyId 申请id
     * @return 处理结果
     */
    @PutMapping("/{applyId}/agree")
    @PermissionAnnotation(menus = {SPECIAL_APPLY})
    public CommonResult agreeApply(@PathVariable Integer applyId) {
        applyService.updateApplyStatus(applyId, true);
        return CommonResult.success();
    }

    /**
     * 拒绝特别申请
     * @param applyId 申请id
     * @return 处理结果
     */
    @PutMapping("/{applyId}/refuse")
    @PermissionAnnotation(menus = {SPECIAL_APPLY})
    public CommonResult refuseApply(@PathVariable Integer applyId) {
        applyService.updateApplyStatus(applyId, false);
        return CommonResult.success();
    }
}
